unused functions/likelihood_gam_closed.R

likelihood_gam_closed <- function(gam, data1, data2) {
  n100 <- data1[1]; n101 <- data1[2]; n110 <- data1[3]
  n111 <- data1[4]; X1 <- data1[5]; Y1 <- data1[6]
  n200 <- data2[1]; n201 <- data2[2]; n210 <- data2[3]
  n211 <- data2[4]; X2 <- data2[5]; Y2 <- data2[6]
  N2 <- sum(data2)

  indices <- expand.grid(i = 0:N2, j1 = 0:Y1, k1 = 0:X1, j2 = 0:Y2, k2 = 0:X2)
  i <- indices$i
  j1 <- indices$j1; k1 <- indices$k1
  j2 <- indices$j2; k2 <- indices$k2

  first_term <- (-n210 - n211 + i - j2 - k2) * gam
  combinations <-
    lchoose(Y1, j1) +
    lchoose(X1, k1) +
    lchoose(Y2, j2) +
    lchoose(X2, k2) -
    lchoose(N2, i)
  betas <-
    lbeta(1 + n100 + Y1 - j1, 1 + n101 + X1 - k1) +
    lbeta(1 + n200 + Y2 - j2, 1 + n201 + X2 - k2) +
    lbeta(1 + n110 + j1, 1 + n111 + k1) +
    lbeta(1 + n210 + j2, 1 + n211 + k2) +
    lbeta(
      1 + n100 + n101 - n210 - n211 + i - j1 - k1 + j2 + k2 + X1 + Y1,
      1 + n110 + n111 + n210 + n211 + i + j1 + j2 + k1 + k2
    )
  sum(exp(first_term + combinations + betas))
}
BriceonWiley/IntegratedLikelihood.R documentation built on Aug. 21, 2020, 11 p.m.